package net.sxnic.item.clpv;

import java.util.List;

import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.spring25.Dao;
import net.sxinfo.core.spring25.DefaultManager;
import net.sxnic.item.catalog.Catalog;
import net.sxnic.item.clpv.dao.ClpvDao;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("clpvManager")
public class DefaultClpvManager extends DefaultManager<Clpv, ClpvDao, String>
		implements ClpvManager {

	@Autowired
	private ClpvDao clpvDao;

	@Override
	protected Dao<Clpv, String> getEntityDao() {
		return clpvDao;
	}

	@Override
	public void deleteByCatalog(Catalog catalog) {
		HibernateCriteria hc = new HibernateCriteria();
		Criterion dc = null;
		if (catalog.getParent() == null) {
			// 大类别
			dc = Restrictions.like("pvName", catalog.getAlias() + "_");
		} else {
			//小类别
			dc = Restrictions.like("pvName", catalog.getParent().getAlias()
					+ "." + catalog.getCode() + "_");
		}

		hc.add(dc);
		
		List<Clpv> list = clpvDao.getByCriteria(hc);
		
		for(Clpv c:list){
			clpvDao.delete(c);
		}
	}

}
